extends Node2D

# 移动速度（像素/秒）
var move_speed = 100
# 初始位置
var initial_position = Vector2.ZERO
# 目标移动距离
var target_distance = 1000
# 已移动距离
var moved_distance = 0
# 是否正在移动
var is_moving = true

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	# 获取MountShip节点并记录初始位置
	var mount_ship = $MountShip
	if mount_ship:
		initial_position = mount_ship.position

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
	# 如果还在移动状态
	if is_moving:
		var mount_ship = $MountShip
		if mount_ship:
			# 计算这一帧要移动的距离
			var move_step = move_speed * delta
			
			# 检查是否会超过目标距离
			if moved_distance + move_step >= target_distance:
				# 如果会超过，就只移动到目标距离
				mount_ship.position.x = initial_position.x + target_distance
				moved_distance = target_distance
				is_moving = false
				_notify_goblins_goAshore(mount_ship)
			else:
				# 正常移动
				mount_ship.position.x += move_step
				moved_distance += move_step

func _notify_goblins_goAshore(root: Node) -> void:
	# 递归遍历MountShip子树，调用带有goAshore方法的节点
	if root and root.has_method("goAshore"):
		root.goAshore()
	if root:
		for child in root.get_children():
			_notify_goblins_goAshore(child)
